<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


    <script>
        //9.ES中的面向对象
        // var person = {
        //     name:'tom',
        //     age:30,
        //     showName:()=>{
        //         alert(this.name);
        //     }
        // }

        // person.showName();


        // function Person(name,age) {
        //     this.name = name;
        //     this.age = age;
        // }

        // Person.prototype.showName = function() {
        //     return this.name;
        // }

        // Person.prototype.showAge = function() {
        //     return this.age;
        // }

        //ES6中会有类的概念(class)
        // 类         class
        // 构造函数    constructor

        class Person1{ //类
            // constructor(name,age){
            //     this.name = name;
            //     this.age = age;
            // }

            constructor(school) {
                this.school = school;
            }

            showName() {
                return this.name;
            }

            showAge() {
                return this.age;
            }

            showSchool(){
                return this.school;
            }
        }

        var p1 = new Person1("foreknow");
        alert(p1.showSchool()); //在ES6中每个类只能有一个构造函数，程序在运行的时候报错

        // class Person{ //类
        //     constructor(name='default',age=0){
        //         this.name = name;
        //         this.age = age;
        //     }

        //     showName() {
        //         return this.name;
        //     }

        //     showAge() {
        //         return this.age;
        //     }
        // }
        // 定义类
        class student{

            // 构造函数
            constructor(name,age){
                this.name = name;
                this.age = age;
            }

            // 定义方法
            showname (){
                return this.name;
            }

        }

        var m1 = new Student("颤三",100);
        
        alert(m1.showname());


        class Person{ //类
            constructor(name='default',age=0){
                this.name = name;
                this.age = age;
            }

            showName() {
                return this.name;
            }

            showAge() {
                return this.age;
            }
        }

        class Worker extends Person {
            constructor(name,age,job='自由职位者'){
                super(name,age);
                this.job = job;
            }
            showJob(){
                return this.job;
            }
        }

        var p1 = new Person();
        alert(p1.showName());

        var w1 = new Worker('good time',20);
        alert(w1.showAge());
        alert(w1.showJob())
    </script>
</head>
<body>
    
</body>
</html>